#define _CRT_SECURE_NO_WARNINGS 1
#pragma warning(disable:6031)



//https://leetcode.cn/problems/sort-colors/

class Solution {
public:
    void sortColors(vector<int>& nums) {
        int left = -1, right = nums.size(), i = 0;
        while (i < right)
        {
            if (nums[i] == 0)
            {
                swap(nums[++left], nums[i++]);
            }
            else if (nums[i] == 1)
            {
                i++;
            }
            else if (nums[i] == 2)
            {
                swap(nums[--right], nums[i]);
            }
        }

    }
};